package me.ilvc.taotao.controller;

import me.ilvc.taotao.model.TbItem;
import me.ilvc.taotao.result.EasyUIResult;
import me.ilvc.taotao.result.TaotaoResult;
import me.ilvc.taotao.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: iLvc
 * @Date：Create in 20:17 2017/8/1
 * @Description:
 * @Modified By:
 */
@Controller
public class ItemController {
    @Autowired
    private ItemService itemService;

    @RequestMapping("/item/{itemId}")
    @ResponseBody
    public TbItem getItenByid(@PathVariable("itemId") Long itemId){

        Integer id= Math.toIntExact(itemId);

        TbItem item = itemService.findById(id);
        return item;
    }

    @RequestMapping("/item/list")
    @ResponseBody
    public EasyUIResult getItemList(int page,int rows){

        EasyUIResult result = (EasyUIResult) itemService.getItemList(page,rows);
        return result;
    }

    @RequestMapping("/item/save")
    @ResponseBody
    public TaotaoResult saveItem(TbItem item, String desc) throws Exception {
        //添加商品信息
        itemService.saveItem(item, desc, null);
        return TaotaoResult.ok();
    }
}
